<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<title>数据字典展示列表页面</title>
		<%@ include file="../../common/jsp/header.jsp"%>

		<link href="<%=path%>static/css/plugins/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet">
		<script type="text/javascript" src="<%=path%>/static/js/plugins/ztree/jquery.ztree.core-3.5.js"></script>
		<script language="JavaScript">

			function abc() {

				$("#searchForm").attr('action', root+"type/queryById.do").submit();
			}

			function beforeClick(treeId, treeNode) {

			}

			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("tree"),
						nodes = zTree.getSelectedNodes(),
				id="";
				nodes.sort(function compare(a,b){return a.id-b.id;});
				for (var i=0, l=nodes.length; i<l; i++) {
					id +=nodes[i].id + ",";
				}
				if (id.length > 0 ) id = id.substring(0, id.length-1);
				var gamTypeId=$("#gamTypeId");
				gamTypeId.attr("value",id);
			}

			$(function () {
				var tree;
				var setting = {
					view: {
						dblClickExpand: false
					},
					data: {
						simpleData: {
							enable: true
						}
					},
					callback: {
						beforeClick: beforeClick,
						onClick: onClick
					},
					view: {
						fontCss: getFontCss
					}
				};
				$.post(root+"type/queryAlltype.do",function (zNodes) {
					tree=$.fn.zTree.init($("#tree"), setting, zNodes);
				},"json")

				$("#queryByName").click(function () {
					var name=$("#search").val();
					var node=tree.getNodeByParam("name",name,"");
					node.highlight=true;
					tree.updateNode(node);
					tree.selectNode(node);
				});


                $("#deleteType").click(function () {
                   var url = root + $("#deleteType").attr("name");
                    swal({
                        title: "确定要删除吗?",
                        text: "删除后将无法恢复当前记录!",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "是的, 不后悔!",
                        cancelButtonText: "算了, 再想想!",
                        closeOnConfirm: false,
                        closeOnCancel: false
                    }, function(isConfirm){
                        if (isConfirm) {
                            swal("成功!", "删除成功,再也找不回来了.", "success");
                                $("#searchForm").attr('action', url).submit();
                        } else {
                            swal("取消", "吓死了,幸亏没删了!", "error");
                        }
                    });
                });
			});
			function getFontCss(treeId, treeNode) {
				return (!!treeNode.highlight) ? {color:"#A60000", "font-weight":"bold"} : {color:"#333", "font-weight":"normal"};
			}
		</script>

	</head>
	<body>
		<div class="wrapper wrapper-content animated fadeInRight">
			<div class="ibox float-e-margins">
				<form id="searchForm" action="">
					<input type="hidden" name="gamTypeId" id="gamTypeId"/>
				<div class="col-sm-12">
					<!-- ------------按钮组 start------------ -->
	                <div class="alert alert-success" role="alert">物资种类详细信息</div>
                    <div class="col-sm-2">
                        <input class="form-control" id="search" name=""  type="text" />
                    </div>
	                <div class="col-sm-8">
<%--	                	<div class="btn-group hidden-xs" role="group">--%>
                			<button type="button" class="btn btn-primary" data-toggle="modal" id="create" name="masterialstype/create.jsp">
	                            <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>添加
	                        </button>
	                        <button type="button" class="btn btn-success"  id="updateTree"  name="" onclick="abc()">
	                            <i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>修改
	                        </button>
	                        <button type="button" class="btn btn-danger" data-toggle="modal" id="deleteType" name="type/delete.do">
	                            <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>删除
	                        </button>
							<button type="button" class="btn btn-danger" data-toggle="modal" id="queryByName" name="masterialstype/delete.do">
								<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>查询
							</button>
<%--		                 </div>--%>
	                </div>

	                 <!-- ------------按钮组 end------------ -->
			     </div>
					<div class="form-group">
						<div class="col-sm-4">
							<table class="table table-striped table-bordered table-hover table-condensed">

								<ul id="tree" class="ztree" style="margin-top:0; width:160px;"></ul>

							</table>
						</div>
					</div>
			     </form>
			</div>
		</div>
	</body>
</html>